package com.peng.servlet;

import com.peng.dao.impl.regionDaoImpl;
import com.peng.dao.impl.userDaoImpl;
import com.peng.dao.regionDao;
import com.peng.dao.userDao;
import com.peng.entity.user;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created by 欧阳欣鹏 on 2018/8/14.
 */
public class UserUpdServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        regionDao region = new regionDaoImpl();
        request.setCharacterEncoding("utf-8");
        PrintWriter out = response.getWriter();
        user u = new user();
        u.setUid(Integer.parseInt(request.getParameter("uid")));
        u.setUname(request.getParameter("uname"));
        u.setUphone(request.getParameter("phone"));
        u.setUpassword(request.getParameter("pwd"));
        String Uprovince = request.getParameter("province") + "省";
        String Ucity = request.getParameter("city");
        String Ucounty = request.getParameter("area");
        u.setUprovince(region.findCity(Uprovince));
        u.setUcity(region.findCity(Ucity));
        u.setUcounty(region.findCity(Ucounty));
        u.setUaddress(request.getParameter("address"));
        u.setUsex(request.getParameter("usex"));
        u.setOpenid(request.getParameter("openid"));
        u.setCheck(1);
        u.setUtype(5);
        u.setUimage("WaterPurifiersrcmainimages头像");
        u.setUemail(request.getParameter("email"));
        userDao us = new userDaoImpl();
        int i = us.update(u);
        if (i >0 ) {
            response.sendRedirect("ChaServlet");
        } else {
            out.print("<script language='javascript'>history.go(-1);alert('新增失败');</script>");
        }

        out.flush();
        out.close();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
